#################################################################
## Purpose:REPLICATION for "Criminal Victimization and Agency Attitudes in Mexico"
## Author: Cassy Dorff, 2024
## Step 2: All models (MS & Appendix)    
#################################################################

#################################################################
rm(list=ls())
source(paste0("~/Desktop/replication/0_setup.R"))

# load the data
load(file=paste0(pathData,"1_nationalsample_data.rda"))
load(file=paste0(pathData,"2_oversample_data.rda"))

# short name
ndata <- national

# examine
table(ndata$dv2)
table(ndata$victim_score_combined)
str(ndata)

# class checks
is.ordered(ndata$partyID)
is.numeric(ndata$age)
is.numeric(over$age)
class(ndata$javier)

#################################################################

#################################################################
# MODELING
# set ref to largest group (vote)
# results for national sample (exclude oversample)
ndata$ref<-relevel(ndata$dv2, ref="Vote")
class(ndata$ref)
#################################################################

#################################################################
# H1 MODELS

# model1: H1
model1<- multinom(ref ~ victim_score_combined
                        + region,
                        Hess=TRUE, maxit=400, data=ndata)

save(model1 , file = paste0(pathData, "model1_results.rda"))

# model 2: h1 + controls 
model2<- multinom(ref ~ victim_score_combined 
                        + age + gender
                        + edu  + javier
                        + region,
                        Hess=TRUE, maxit=400, data=ndata)
save(model2 , file = paste0(pathData, "model2_results.rda"))
#################################################################

#################################################################
# H2 MODELS

# create subsample of population that did not experience DIRECT vic
no_direct_vic <- ndata %>%
  filter(victim_score_combined == "0")

# model 3: H2
model3<- multinom(ref ~ victim_net_only_bin 
                        + region,
                        Hess=TRUE, maxit=400, data=no_direct_vic)
save(model3 , file = paste0(pathData, "model3_results.rda"))

# model 4: H2 + controls
model4<- multinom(ref ~ victim_net_only_bin 
                        + age + gender
                        + edu  + javier +
                        region,
                        Hess=TRUE, maxit=400, data=no_direct_vic)
save(model4 , file = paste0(pathData, "model4_results.rda"))
#################################################################

#################################################################
# Oversample models

# set reference
over$ref<-relevel(over$dv2, ref="Vote")

# h1 + controls + oversample
model5<- multinom(ref ~ victim_score_combined
                        + age + gender
                        + edu + javier,
                        Hess=TRUE, maxit=400, data=over)

save(model5 , file = paste0(pathData, "model5_results.rda"))

# h2 + oversample
# make subsample of those with no direct victimization
no_direct_vic_over <- over %>%
  filter(victim_score_combined == "0")

model6<- multinom(ref ~ victim_net_only_bin 
                  + age + gender,
                  Hess=TRUE, maxit=400, 
                  data=no_direct_vic_over)

save(model6 , file = paste0(pathData, "model6_results.rda"))
#################################################################

#################################################################
# models with alternative controls
# robustness checks

# main model with rural and voted added 
model7<- multinom(ref ~ victim_score_combined 
                  + age + gender
                  + edu + javier
                  + relevel(urban_rural, ref = "Urbano")
                  + voted
                  + region,
                  Hess=TRUE, maxit=400, data=ndata)
save(model7 , file = paste0(pathData, "model7_results.rda"))

# main model alternative controls with SES 
model8<- multinom(ref ~ victim_score_combined 
                  + age + gender
                  + lightbulbs
                  + javier
                  + region,
                  Hess=TRUE, maxit=400, data=ndata)
save(model8 , file = paste0(pathData, "model8_results.rda"))

# main model with alternative controls for political engagement
model9<- multinom(ref ~ victim_score_combined
                        + relevel(party_ID, ref = "Other")
                        + community_bin 
                        + voted
                        + region,
                        Hess=TRUE, maxit=400, data=ndata)
save(model9, file = paste0(pathData, "model9_results.rda"))

# main model with alternative controls for participation/involvement
model10<- multinom(ref ~ victim_score_combined
                  + civil_res_part
                  + auto_support
                  + region,
                  Hess=TRUE, maxit=400, data=ndata)

save(model10 , file = paste0(pathData, "model10_results.rda"))



